package com.hhp.cloud.shop.product.controller;

import java.util.Arrays;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.core.util.StrUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hhp.cloud.shop.product.entity.ProductAttrValueEntity;
import com.hhp.cloud.shop.product.service.ProductAttrValueService;
import com.hhp.cloud.shop.common.core.result.R;



/**
 * spu属性值
 *
 * @author hhp
 * @email 2437579794@qq.com
 * @date 2021-12-07 15:15:44
 */
@RestController
@RequestMapping("/api/v1/product/productAttrValue")
public class ProductAttrValueController {
    @Autowired
    private ProductAttrValueService productAttrValueService;

    /**
     * 列表
     */
    @ApiOperation(value = "spu属性值分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "attrName", value = "属性名", paramType = "query", dataType = "String")
    })
    @GetMapping
    public R list(Integer page, Integer limit, String attrName){
        return R.ok().setData(productAttrValueService.pageMaps(
                new Page<>(page, limit),
                new LambdaQueryWrapper<ProductAttrValueEntity>()
                        .like(StrUtil.isNotBlank(attrName), ProductAttrValueEntity::getAttrName, attrName)));
    }


    /**
     * 信息
     */
    @ApiOperation(value = "spu属性值详情")
    @ApiImplicitParam(name = "id", value = "spu属性值id", required = true, paramType = "path", dataType = "Long")
    @GetMapping("/{id}")
    public R info(@PathVariable("id") Long id){
		return R.ok().setData(productAttrValueService.getById(id));
    }

    /**
     * 保存
     */
    @ApiOperation(value = "新增spu属性值")
    @PostMapping
    public R save(@RequestBody ProductAttrValueEntity productAttrValue){
		productAttrValueService.save(productAttrValue);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改spu属性值")
    @PutMapping("/{id}")
    public R update(@PathVariable("id") Long id, @RequestBody ProductAttrValueEntity productAttrValue){
		productAttrValueService.updateById(productAttrValue);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除spu属性值")
    @DeleteMapping
    public R delete(@RequestBody Long[] ids){
		productAttrValueService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
